<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .headere {
            height: 6.25rem;
            width: 100%;
            display: flex;
            justify-content: center;
            background-color: skyblue;
            align-items: center;
            color: white;
            font-size: 1.875rem;
            transition: all 1s linear;

            position: fixed;
            top: -6.25rem;
            left: 0;

        }

        .gotop {
            width: 3.125rem;
            height: 3.125rem;
            background-color: rebeccapurple;
            font-size: 1.25rem;
            color: #fff;
            text-align: center;

            position: fixed;
            bottom: 0;
            right: 0;
            display: none;


        }


        body {
            height: 187.5rem;
        }
    </style>

</head>

<body>

    <div class="headere">顶部通栏</div>
    <div class="gotop"> 回到顶部</div>

    <script>
        var headere = document.querySelector('.headere')
        var gotop = document.querySelector('.gotop')

        window.onscroll = function () {
            var height = document.documentElement.scrollTop || document.body.scrollTop
            console.log(height);
            if (height >= 300) {
                headere.style.top = '0px'
                gotop.style.display = 'block'
            } else {
                headere.style.top = '-100px'

                gotop.style.display = 'none'
            }
        }
        gotop.onclick = function () {
            window.scrollTo({
                top:0,
                behavior:'smooth'
            })
        }


    </script>
</body>

</html>